/**
 * @file   PacketPayload.h
 * @author Djuro Drljaca (djurodrljaca@gmail.com)
 * @date   2013-03-10
 * @brief  DataBus Packet Payload.
 *
 * Copyright (C) 2013  Djuro Drljaca <djurodrljaca@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef LIBDATABUS_COMMON_PACKETPAYLOAD_H
#define LIBDATABUS_COMMON_PACKETPAYLOAD_H

#include <DataBus/Common/Common.h>

namespace DataBus
{
/**
 * @brief The PacketPayload class
 */
class DATABUSSHARED_EXPORT PacketPayload
{
public:
    /**
     * @brief Constructor for PacketPayload
     */
    PacketPayload();

    /**
     * @brief Constructor for PacketPayload
     *
     * @param data  Payload data
     */
    PacketPayload(const QByteArray &data);

    /**
     * @brief Reads the payload data
     *
     * @return Payload data
     */
    QByteArray getData() const;

    /**
     * @brief Set the payload length
     *
     * @param data  Payload data
     */
    void setData(const QByteArray &data);

    /**
     * @brief Convert packet header to byte array
     *
     * @return Byte array with packet header
     */
    QByteArray toBinary() const;

    /**
     * @brief Parse data for a valid payload
     *
     * @param packetPayload Data Input data
     * @param startIndex    Start of payload in input data
     * @param payloadSize   Number of bytes in the payload data (without payload checksum!)
     *
     * @param[out] packetPayload    Output object
     *
     * @retval true     Successfully parsed the packet header
     * @retval false    Failed to parse the packet header
     *
     */
    static bool parse(const QByteArray &packetPayloadData,
                      const int startIndex,
                      const int payloadSize,
                      PacketPayload *packetPayload);

private:
    /**
     * @brief Packet payload data
     */
    QByteArray m_data;
};
}

#endif // LIBDATABUS_COMMON_PACKETPAYLOAD_H
